package utils.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

import entity.ClassifoImgResult;
import fragment.classicfragments.ClassifoimgViewpageFragment;

/**
 * Created by dllo on 15/11/20.
 */
public class ViewpagerAdapter extends FragmentPagerAdapter {
    private List<ClassifoImgResult.FocusImagesEntity.ListEntity> list;

    public void addData(List<ClassifoImgResult.FocusImagesEntity.ListEntity> datas){
         list = datas;
        notifyDataSetChanged();
    }

    public ViewpagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        ClassifoImgResult.FocusImagesEntity.ListEntity listEntity = list.get(position % list.size());
        String imgUrl = listEntity.getPic();

        return ClassifoimgViewpageFragment.getInstance(imgUrl);
    }

    @Override
    public int getCount() {
        return list != null && list.size() > 0 ? Integer.MAX_VALUE : 0;
    }
}
